package main

import (
	"fmt"
	"math"
	"errors"
)


type error interface { 
	Error() string
}

func Sqrt(f float64) (float64, error) {

    if f < 0 {
        return 0, errors.New("math: square root of negative number")
    }
	// 实现
	z := float64(1)
	tmp := float64(0)
	for math.Abs(tmp - z) > 0.0000000001 {
		tmp = z
		z = (z + f/z)/2
	}
	return z, errors.New(" right")
}

func main() {

	// result, err:= Sqrt(-1)

	// fmt.Printf("result is %v \n", result)
	// if err != nil {
	// 	fmt.Println(err)
	// }


	result, err:= Sqrt(4)

	fmt.Printf("result is %v \n", result)
	if err != nil {
		fmt.Println(err)
	}

	fmt.Printf("4 sqrt is %f \n", math.Sqrt(4))
}